<template>
  <div class="Repairinvoice">
    <a-card>
      <a-form :form="form">
        <a-row :gutter="30">
          <a-col :span="8">
            <a-form-item label="补货时间" :label-col="{ span: 6 }" :wrapper-col="{ span: 16,offset:1}">
              <a-date-picker v-decorator="['time']" format="YYYY-MM-DD HH:mm:ss"></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="补货状态" :label-col="{ span: 6}" :wrapper-col="{ span: 16, offset: 1}">
              <a-select v-decorator="['cruise']" placeholder="正常">
                <a-select-option :value="-1">全部</a-select-option>
                <a-select-option :value="1">待处理</a-select-option>
                <a-select-option :value="2">已上货</a-select-option>
                <a-select-option :value="3">已确认回库</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="设备编号" :label-col="{ span: 6}" :wrapper-col="{ span: 16, offset: 1}">
              <a-input placeholder="请输入" v-decorator="['facilityNumber']" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="30">
          <a-col :span="8">
            <a-form-item label="创建人" :label-col="{ span: 5}" :wrapper-col="{ span: 16,offset:2 }">
              <a-input placeholder="请输入" v-decorator="['creatman']" />
            </a-form-item>
          </a-col>
          <a-col :span="16" :style="{ textAlign: 'right'}">
            <a-button type="primary" @click="search()">查询</a-button>
            <a-button type="dashed" style="margin: 0 1%" @click="listExport()">导出</a-button>
            <a-button @click="handleReset()" style="margin-right:4%">重置</a-button>
            <router-link to="/home/repertoryadmin/repairinvoice/realcreat">
              <a-button type="primary" style="margin-right:8px">创建</a-button>
            </router-link>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <!-- //进行下面得表格操作 -->
    <a-card style="margin-top:2%">
      <a-table
        :columns="columns"
        :dataSource="data"
        @change="handleTablePop"
        :bordered="true"
        :pagination="pagination"
        :rowKey="record => record.code"
      >
        <template slot="name" slot-scope="text" href="javascript:;">{{text}}</template>
        <template slot="action" slot-scope="text,record">
          <span class="blue" @click="detailjump(text,record)">详情</span>
          <!-- <a href="javascript:;">Invite 一 {{record.name}}</a>
          <a-divider type="vertical" />-->
          <!-- <a-divider type="vertical" />
      <a href="javascript:;" class="ant-dropdown-link">
        More actions <a-icon type="down" />
          </a>-->
        </template>

        <template slot="repaireStatus" slot-scope="text,record">
          <span>{{record.status==1?"待处理":(record.status==2? "已上货":"以确认回库")}}</span>
        </template>
      </a-table>
    </a-card>
    <!-- //进行下面得表格操作 -->

    <!-- 待下架清单 -->
  </div>
</template>

<script>
// V-DERACTOR  用来获取输入框的数据的
const columns = [
  {
    //dataindex是用来渲染数据的
    dataIndex: "code",
    title: "补货单号",
    align: "center"

    // scopedSlots: { customRender: "name" }
  },
  {
    dataIndex: "replenishmentTime",
    title: "补货时间",

    align: "center"
  },
  {
    title: "设备号",
    dataIndex: "devCode",
    align: "center"
    // scopedSlots: { customRender: "facilityNumber" }
  },
  {
    title: "点位名称",
    dataIndex: "posName",
    align: "center"
    // scopedSlots: { customRender: 'tags' },
  },
  {
    title: "点位地址",
    dataIndex: "posAddr",
    align: "center"
    //   scopedSlots: { customRender: 'tags' },
  },
  {
    title: "补货状态",
    dataIndex: "status",
    align: "center",
    scopedSlots: { customRender: "repaireStatus" }
  },
  {
    title: "库存比例",
    dataIndex: "inventoryRatio",
    align: "center"
    //   scopedSlots: { customRender: 'tags' },
  },
  {
    title: "巡柜员",
    dataIndex: "employeeName",
    align: "center"
    //   scopedSlots: { customRender: 'tags' },
  },
  {
    title: "创建人",
    dataIndex: "createName",
    align: "center"
    // scopedSlots: { customRender: "creatman" }
  },

  {
    title: "操作",
    align: "center",
    scopedSlots: { customRender: "action" }
  }
];

//指的是表格里面的数据--并对此数据进行遍历
const data = [
  {
    key: "1"
  }
];
// const data = [{
//   key: '1',
//   name: 'John Brown',
//   age: 32333,
//   address: 'New York No. 1 Lake Park',
//   tags: ['nice', 'developer'],
// }, {
//   key: '2',
//   name: 'Jim Green',
//   age: 42,
//   address: 'London No. 1 Lake Park',
//   tags: ['loser'],
// }, {
//   key: '3',
//   name: 'Joe Black',
//   age: 32,
//   address: 'Sidney No. 1 Lake Park',
//   tags: ['cool', 'teacher'],
// }];

export default {
  data() {
    return {
      expand: false,
      //上面绑定了form表单所以后面用this.creatform
      form: this.$form.createForm(this),

      //表格中自带的分页器
      pagination: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["10", "20", "30", "40"], //每页条数选择器
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        }, // 总数展示
        pageSize: 10, //每页条数
        defaultCurrent: 1, //默认当前页
        current: 1, //当前页
        total: 50 //数据总条数
      },
      //表格中自带的分页器

      // data里面存储的是list的数据
      data: [],
      // deviceAgentId:'',
      columns
    };
  },
  computed: {
    count() {
      return this.expand ? 11 : 7;
    }
  },
  methods: {
    //重置方法
    handleReset() {
      this.form.resetFields();
    },

    //分页可以点击的方法
    handleTablePop(pagination, filters, sorter) {
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.pagination = pager;
      this.handleReset();
      //必须要查询
      this.search();
    },
    //分页可以点击的方法

    // 补货单搜索
    search() {
      //组件中的内置的方发获取values的值
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/replenishmentOrder/search", {
          loginToken: this.$store.state.loginToken,
          pageNum: this.pagination.current,
          pageSize: this.pagination.pageSize,
          // ----以上三个是必留
          // --创建人
          createName: values.creatman,
          //--设备编号
          devCode: values.facilityNumber,
          //捕获状态
          status: values.cruise,
          //捕获时间
          replenishmentTime: values.time
        })
        .then(response => {
          //成功后的回调函数
          console.log(response.data);
          this.data = response.data.data.list;
          //总条数-每一页的条数-当前的数
          this.pagination.total = response.data.data.total;
          this.pagination.pageSize = response.data.data.pageSize;
          this.pagination.current = response.data.data.pageNum;
        })
        .catch(error => {
          console.log(error);
        });
    },

    //补货单导出
    listExport() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(
          this.baseUrl + "/replenishmentOrder/export",
          {
            loginToken: this.$store.state.loginToken,
            createName: values.creatman,
            //--设备编号
            devCode: values.facilityNumber,
            //捕获状态
            status: values.cruise,
            //捕获时间
            replenishmentTime: values.time
          },
          { responseType: "arraybuffer" }
        )
        .then(response => {
          console.log(response);
          if (response.status == "200") {
            const aLink = document.createElement("a");
            let blob = new Blob([response.data], {
              type: "application/vnd.ms-excel"
            });
            aLink.href = URL.createObjectURL(blob);
            aLink.download = "补货单表";
            aLink.click();
            document.body.appendChild(aLink);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //创建补货单下架清单

    //详情跳页传ID
    detailjump(text, record) {
      console.log(record);
      //设备编号id
      var deviceAgentId = record.deviceAgentId;
      //补货单id
      var replenishmentOrderId = record.replenishmentOrderId;
      //待补货时间
      var replenishmentTime = record.replenishmentTime;
      var devCode = record.devCode;
      var posAddr = record.posAddr;
      var employeeName = record.employeeName;

      replenishmentTime;
      // 存储到vuex里面的数据
      this.$store.commit("deviceAgentId", deviceAgentId);
      this.$store.commit("replenishmentOrderId", replenishmentOrderId);
      this.$store.commit("replenishmentTime", replenishmentTime);
      this.$store.commit("devCode", devCode);
      this.$store.commit("posAddr", posAddr);
      this.$store.commit("employeeName", employeeName);
      this.$router.push({
        path: "/home/repertoryadmin/repairinvoice/createrepaire"
      });
    }
  },
  created() {
    this.search();
  }
};
</script>

<style>
.Repairinvoice {
  width: 100%;
}
</style>
